#ifndef __PREFIXKNIT_H__
#define __PREFIXKNIT_H__

int pk_init_data(MH_KNIT *p, int row, int type, int manual_loop);
void pk_clear_data(MH_KNIT *p);
short pk_get_loop_end(MH_KNIT *p, int row);
short pk_get_loop_num(MH_KNIT *p, int row);
int pk_get_cnt_buf(MH_KNIT *p, KNIT_PAGE *buf_out, int row);
/*
 *
 */
void pk_convert_economy(MH_KNIT *p);

#define SET_SYS1_FPR(buf, row)              \
    buf[0] = (row) & 0x00FF;                \
    buf[1] = ((row) & 0xFF00) >> 8

#define SET_SYS1_BPR(buf, row)              \
    buf[10] = (row) & 0x00FF;               \
    buf[11] = ((row) & 0xFF00) >> 8

#define SET_SYS2_FPR(buf, row)              \
    buf[20] = (row) & 0x00FF;               \
    buf[21] = ((row) & 0xFF00) >> 8

#define SET_SYS2_BPR(buf, row)              \
    buf[30] = (row) & 0x00FF;               \
    buf[31] = ((row) & 0xFF00) >> 8

#define SET_SYS1_FC(buf, cmd)           buf[2] = (cmd)
#define SET_SYS1_BC(buf, cmd)           buf[12] = (cmd)
#define SET_SYS2_FC(buf, cmd)           buf[22] = (cmd)
#define SET_SYS2_BC(buf, cmd)           buf[32] = (cmd)

#define SET_SYS1_FAC(buf, color)            \
    buf[3] = (color) & 0x00FF;              \
    buf[4] = ((color) & 0xFF00) >> 8

#define SET_SYS1_FHC(buf, color)            \
    buf[7] = (color) & 0x00FF;              \
    buf[8] = ((color) & 0xFF00) >> 8

#define SET_SYS1_BAC(buf, color)            \
    buf[13] = (color) & 0x00FF;             \
    buf[14] = ((color) & 0xFF00) >> 8

#define SET_SYS1_BHC(buf, color)            \
    buf[17] = (color) & 0x00FF;             \
    buf[18] = ((color) & 0xFF00) >> 8

#define SET_SYS2_FAC(buf, color)            \
    buf[23] = (color) & 0x00FF;             \
    buf[24] = ((color) & 0xFF00) >> 8

#define SET_SYS2_FHC(buf, color)            \
    buf[27] = (color) & 0x00FF;             \
    buf[28] = ((color) & 0xFF00) >> 8

#define SET_SYS2_BAC(buf, color)            \
    buf[33] = (color) & 0x00FF;             \
    buf[34] = ((color) & 0xFF00) >> 8

#define SET_SYS2_BHC(buf, color)            \
    buf[37] = (color) & 0x00FF;             \
    buf[38] = ((color) & 0xFF00) >> 8

#define SET_SYS1_YC(buf, yc)                \
    buf[81] = (yc) & 0x00FF;                \
    buf[80] = ((yc) & 0xFF00) >> 8

#define SET_SYS2_YC(buf, yc)                \
    buf[84] = (yc) & 0x00FF;                \
    buf[83] = ((yc) & 0xFF00) >> 8

#define SET_LOOP_START(buf, start)          \
    buf[122] = (start) & 0x00FF;            \
    buf[123] = ((start) & 0xFF00) >> 8

#define SET_LOOP_END(buf, end)              \
    buf[124] = (end) & 0x00FF;              \
    buf[125] = ((end) & 0xFF00) >> 8

#define SET_LOOP_NUM(buf, num)              \
    buf[126] = (num) & 0x00FF;              \
    buf[127] = ((num) & 0xFF00) >> 8

#define PK_ROUND(row)       (row + p->pk_data.pcnt.rows)


#endif /* __PREFIXKNIT_H__ */
